import com.alibaba.dashscope.Application;
import com.alibaba.dashscope.ApplicationParam;
import com.alibaba.dashscope.ApplicationResult;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.exception.InputRequiredException;

/**
 * 测试AI调用的简单脚本
 * 用于验证DashScope API是否正常工作
 */
public class TestAiCall {
    
    public static void main(String[] args) {
        // 请替换为您的实际配置
        String apiKey = "your-api-key-here";
        String appId = "your-app-id-here";
        String testMessage = "你好，请简单介绍一下你自己";
        
        System.out.println("开始测试AI调用...");
        System.out.println("测试消息: " + testMessage);
        System.out.println("App ID: " + appId);
        System.out.println("API Key: " + (apiKey != null ? "已配置" : "未配置"));
        
        try {
            ApplicationParam param = ApplicationParam.builder()
                    .apiKey(apiKey)
                    .appId(appId)
                    .prompt(testMessage)
                    .build();

            System.out.println("参数构建完成，开始调用...");
            
            Application application = new Application();
            ApplicationResult result = application.call(param);
            
            String aiResponse = result.getOutput().getText();
            System.out.println("AI调用成功！");
            System.out.println("AI回复: " + aiResponse);
            
        } catch (NoApiKeyException e) {
            System.err.println("API Key错误: " + e.getMessage());
        } catch (InputRequiredException e) {
            System.err.println("输入参数错误: " + e.getMessage());
        } catch (ApiException e) {
            System.err.println("API调用错误: " + e.getMessage());
            System.err.println("错误代码: " + e.getCode());
        } catch (Exception e) {
            System.err.println("未知错误: " + e.getMessage());
            e.printStackTrace();
        }
    }
} 